package chapter04;

/**
 * ClassName: aaa
 * Package: chapter04
 * Description:
 *
 * @Author fjorid
 * @Create 2025/2/17 20:06
 * @Version 1.0
 */

public class DeleteAndCopy {
    public static void main(String[] args) {
        int oldArr[] = {1, 3, 4, 5, 0, 0, 6, 6, 0, 5, 4, 7, 6, 7, 0, 5};

        int nonZeroIndex = 0;

        // 遍历数组，将非零元素依次放到前面
        for (int i = 0; i < oldArr.length; i++) {
            if (oldArr[i] != 0) {
                oldArr[nonZeroIndex] = oldArr[i];
                nonZeroIndex++;
            }
        }
        for (int num : oldArr) {
            System.out.print(num + " ");
        }
        System.out.println("\t");
        // 将剩余位置置为 0
        for (int i = nonZeroIndex; i < oldArr.length; i++) {
            oldArr[i] = 0;
        }


        for (int num : oldArr) {
            System.out.print(num + " ");
        }
    }
}